package com.example.cyh.bczapp.Code.BLL;

import com.example.cyh.bczapp.Code.Helper.HttpHelper;
import com.example.cyh.bczapp.Code.Model.PlanInfEntity;
import com.google.gson.Gson;

import java.util.Dictionary;
import java.util.Hashtable;

/**
 * Created by cyh on 2017/5/23.
 */

public class PlanBLL {
    private final String BaseUrl = "http://123.207.86.30/public/index.php/db/";

    public PlanInfEntity GetPlan(String planid) {
        String url = BaseUrl + "/Plancontrol/GetPlan";
        Dictionary<String, String> param = new Hashtable();
        param.put("p_id", planid);
        try {
            String back = HttpHelper.POST(url, param);
            Gson gson = new Gson();
            return gson.fromJson(back, PlanInfEntity.class);
        } catch (Exception ex) {
            return null;
        }
    }

    public String AddPlan(PlanInfEntity rd) {
        String url = BaseUrl + "Plancontrol/Add";
        Gson gson = new Gson();
        Dictionary<String, String> param = new Hashtable();
        param.put("rd", gson.toJson(rd));
        try {
            String back = HttpHelper.POST(url, param);
            return back;
        } catch (Exception ex) {
            return "false";
        }
    }

    public String AlertPlan(PlanInfEntity rd) {
        String url = BaseUrl + "Plancontrol/UserAlert";
        Gson gson = new Gson();
        Dictionary<String, String> param = new Hashtable();
        param.put("rd", gson.toJson(rd));
        try {
            String back = HttpHelper.POST(url, param);
            return back;
        } catch (Exception ex) {
            return "false";
        }
    }

    public String DeletPlan(String id) {
        String url = BaseUrl + "Plancontrol/Delet";
        Dictionary<String, String> param = new Hashtable();
        param.put("rdid", id);
        try {
            String back = HttpHelper.POST(url, param);
            return back;
        } catch (Exception ex) {
            return "false";
        }
    }
}
